1. Field of the Invention
The present invention relates to a method for allocating memory in a computer, and more particularly to a method for allocating memory, and the like, when a memory shortage state is generated.
2. Description of the Related Art
Normally, when an application is run on a computer, after the program of this application has been read to memory, processing is executed in accordance with this program. Therefore, in response to a request to run this application, processing is performed in which memory management software allocates memory of the required capacity to this application.
Then, once this allocation has taken place, even if the allocated memory area is not required by the application, because the fact that this area may be recovered is not communicated on each occasion to the memory management software, the free capacity of the memory is normally reduced each time a request to run an application is made, and this ultimately leads to the generation of a memory shortage state.
When such a memory shortage is generated, the memory management software typically executes GC (garbage collection) processing. Such processing searches for and locates sections of the memory in an unused state from those sections of the memory which have already been allocated, and then recovers these memory sections. Such processing makes it possible to increase the free capacity of the memory. The above-described allocation of memory to an application can thus be repeated.
Such a memory management function is implemented by software such as JavaVM (Java Virtual Machine), for example. JavaVM is software which is situated in an OS and in a Java (Registered Trademark of Sun Microsystems Inc., likewise hereinafter) program and which, in addition to comprising a memory management function, also comprises functions for performing thread management, method management, byte code execution, and the like. JavaVM is widely employed in servers that supply services to a plurality of clients over the Internet and other such servers.
FIG. 12 illustrates a conventional memory allocation method performed by such memory management software. First of all, a memory acquisition request is received on the basis of an application execution request by the user (step S21 of FIG. 12) Next, a check is made as to whether or not there is free capacity in the memory that adequately satisfies the required size pertaining to the memory acquisition request (step S22 of FIG. 12). As a result, when a free capacity that adequately satisfies this request exists (“Yes” in step S22 of FIG. 12), memory corresponding to the required size is acquired, and the start address is communicated to the application (step S26 of FIG. 12).
On the other hand, when an adequate memory free capacity does not exist (“No” in step S22 of FIG. 12), the above-described GC processing is executed to recover unused memory (step S23 of FIG. 12). Then, because of the resulting increase in the free capacity of the memory, the free capacity of the memory is checked once again (step S24 of FIG. 12). Here, processing like that of step S22 described above is performed, and in cases where free capacity that adequately satisfies the required size has been obtained(“Yes” in step S24 of FIG. 12), memory corresponding to the required size is acquired and the memory start address is communicated to the application (step S26 of FIG. 12).
Also, when it has not been possible to obtain an adequate free memory capacity (“No” in step S24 of FIG. 12), error processing is performed (step S25 of FIG. 12). That is, the acquisition of memory corresponding to the required size is abandoned, a message to the effect that there is a memory shortage is outputted to the application, and the application is terminated.
As described hereinabove, in conventional memory allocation methods, in the event of a memory shortage state following GC processing, error processing is performed and the application in question is terminated, irrespective of the reason for the memory shortage or the specific status thereof, and so forth. Therefore, in a case such as this, the user is unable to use the application and either abandons usage of the application or makes another usage request.
However, the memory shortage state described above also includes a chronic memory shortage state and a temporary memory shortage state, and because, in the conventional method described above, error processing is immediately performed irrespective of which of these states exists, the following problems are known.
Where the chronic memory shortage state is concerned, because a free capacity satisfying the size required cannot be regularly secured and the probability of memory acquisition is low even over time, the immediate execution of error processing, as performed conventionally, is reasonable.
However, the temporary memory shortage state is one in which, although memory of the required size can be regularly secured, it is temporarily impossible to secure the memory for any reason, and, in such a case, there is the possibility that it will be possible to secure memory of the required size by waiting a short while. It is therefore not advisable to immediately perform error processing to stop the application in question, as was the case conventionally, in the temporary memory shortage state too.
Even if a state that permits usage upon waiting a short while exists, this fact is not known to the user, and hence a user confronted by such error processing will therefore sometimes abandon usage, and thus miss out on a usage opportunity. Also, a user that does not abandon usage but instead, following error processing, repeats the operation to request usage many times over, is able to use the application after a short time has elapsed. However, because a previously inputted value is reset each time error processing takes place, there is a requirement to perform the input operation from the beginning each time the usage request operation is performed, which is inconvenient.
For example, on a Web site that provides a Web service targeting the general public such as “hotel reservations”, “computer price estimates”, or the like, because it is hoped that users visiting this Web site will use such a service as much as possible, the above-described memory shortage state is not preferable in that the opportunity to supply the service is lost and usability for users is poor. Moreover, due to the rapid popularization of the Internet in recent times, the number of users gaining access to such a service is increasing and the environment is increasingly becoming one in which memory shortage states are readily generated. A countermeasure is therefore preferable such that, even if a memory shortage state is generated, error processing is not always performed as it was conventionally, but, instead, an application is allowed to continue running wherever possible in cases of temporary memory shortage.